<?php
/**
 * Specials
 *
 * @package page
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: main_template_vars.php 6912 2007-09-02 02:23:45Z drbyte $
 */

if (MAX_DISPLAY_SPECIAL_PRODUCTS > 0 ) {
  $specials_query_raw = "SELECT p.products_id, p.products_type, pd.products_name, p.products_image, p.products_price,
                                    p.products_tax_class_id, p.products_date_added,  p.products_model,
                                    p.products_quantity, p.products_weight, p.product_is_call,
                                    p.product_is_always_free_shipping, p.products_qty_box_status,
                                    p.master_categories_id,p.product_is_wholesale,p.product_wholesale_min,p.products_price_sample,
                                    p.products_price_retail,p.products_quantity,p.products_quantity_order_min,p.products_status
                         FROM (" . TABLE_PRODUCTS . " p
                         LEFT JOIN " . TABLE_SPECIALS . " s on p.products_id = s.products_id
                         LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id )
                         WHERE p.products_id = s.products_id and p.products_id = pd.products_id and p.products_status = '1'
                         AND s.status = 1
                         AND pd.language_id = :languagesID
                         ORDER BY s.specials_date_added DESC";

  $specials_query_raw = $db->bindVars($specials_query_raw, ':languagesID', $_SESSION['languages_id'], 'integer');
  $specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIAL_PRODUCTS);
  $specials = $db->Execute($specials_split->sql_query);
  $list_box_contents = array();
  
  if($specials->RecordCount()>0){
    $row = 0;
    while (!$specials->EOF) {
      if ($specials->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) {
        $list_box_contents[$row]['products_image'] = '';
      } else {
        $list_box_contents[$row]['products_image'] = $specials->fields['products_image'] ;
      }
      $list_box_contents[$row]['products_name'] = $specials->fields['products_name'];
      $list_box_contents[$row]['products_description'] = zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($specials->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION);
      $list_box_contents[$row]['products_price'] = zen_get_products_base_price($specials->fields['products_id']);
      $list_box_contents[$row]['actual_price'] = $currencies->display_price(zen_get_products_actual_price($specials->fields['products_id']),zen_get_tax_rate($product_check->fields['products_tax_class_id']));
      $list_box_contents[$row]['products_status']=$specials->fields['products_status'];
      if ($specials->fields['product_is_always_free_shipping'] == 0) {
        $list_box_contents[$row]['product_is_always_free_shipping'] = '';
      } else {
        $list_box_contents[$row]['product_is_always_free_shipping'] = '<span class="free_shipping"></span>';
      }
      
      $list_box_contents[$row]['products_quantity_order_min'] = $specials->fields['products_quantity_order_min'];
      $list_box_contents[$row]['products_id'] = $specials->fields['products_id'];
      $list_box_contents[$row]['products_quantity'] = $specials->fields['products_quantity'];
      
      $list_box_contents[$row]['products_price_retail'] = $currencies->display_price($specials->fields['products_price_retail'],zen_get_tax_rate($product_check->fields['products_tax_class_id']));
      $list_box_contents[$row]['products_price_sample'] = $currencies->display_price($specials->fields['products_price_sample'],zen_get_tax_rate($product_check->fields['products_tax_class_id']));
      $list_box_contents[$row]['product_is_wholesale'] = $specials->fields['product_is_wholesale'];
      $list_box_contents[$row]['product_wholesale_min'] = $specials->fields['product_wholesale_min'];
      $specials->MoveNext();
      $row++;
    }
	require($template->get_template_dir('tpl_specials_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_specials_default.php');
  
  }
  
}
?>